<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ Topic与Tag深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.1);
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            border-color: rgba(102, 126, 234, 0.3);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .comparison-table {
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .comparison-table th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-weight: 600;
            padding: 16px;
            text-align: left;
        }
        
        .comparison-table td {
            padding: 16px;
            border-bottom: 1px solid #e5e7eb;
            background: white;
        }
        
        .comparison-table tr:last-child td {
            border-bottom: none;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 32px 0;
        }
        
        .best-practice-card {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 24px;
            border-radius: 16px;
            margin-bottom: 16px;
        }
        
        .tag-badge {
            display: inline-block;
            padding: 4px 12px;
            background: rgba(102, 126, 234, 0.1);
            color: #667eea;
            border-radius: 20px;
            font-size: 14px;
            margin-right: 8px;
            margin-bottom: 8px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border-left: 4px solid #667eea;
            padding: 20px;
            border-radius: 8px;
            margin: 16px 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl font-bold mb-6">RocketMQ 消息分类艺术</h1>
            <p class="text-xl mb-8 opacity-90">深入理解 Topic 与 Tag 的设计哲学与最佳实践</p>
            <div class="flex justify-center space-x-4">
                <span class="tag-badge bg-white bg-opacity-20 text-white">
                    <i class="fas fa-layer-group mr-2"></i>分布式消息
                </span>
                <span class="tag-badge bg-white bg-opacity-20 text-white">
                    <i class="fas fa-code-branch mr-2"></i>架构设计
                </span>
                <span class="tag-badge bg-white bg-opacity-20 text-white">
                    <i class="fas fa-rocket mr-2"></i>高性能
                </span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Topic 概念介绍 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">Topic 的概念和作用</h2>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="card-hover p-6 rounded-xl">
                    <div class="feature-icon">
                        <i class="fas fa-cube"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">基本概念</h3>
                    <p class="text-gray-600">Topic 是 RocketMQ 中消息的一级分类，是生产者发送消息和消费者订阅消息的基本单位。所有消息都必须归属于某个 Topic。</p>
                </div>
                
                <div class="card-hover p-6 rounded-xl">
                    <div class="feature-icon">
                        <i class="fas fa-network-wired"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">物理结构</h3>
                    <p class="text-gray-600">Topic 可跨多个 Broker 存储，每个 Broker 上的 Topic 被划分为多个读写队列（MessageQueue），支持高并发和数据分片。</p>
                </div>
                
                <div class="card-hover p-6 rounded-xl">
                    <div class="feature-icon">
                        <i class="fas fa-route"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">路由管理</h3>
                    <p class="text-gray-600">Topic 的路由信息由 NameServer 管理，包含 Topic 所在 Broker、队列数量等元数据，Producer 和 Consumer 通过它获取路由。</p>
                </div>
            </div>

            <!-- Topic 架构图 -->
            <div class="card-hover p-8 rounded-xl mb-8">
                <h3 class="text-xl font-semibold mb-4">Topic 分布式架构</h3>
                <div class="mermaid">
                    graph TB
                        subgraph "NameServer 集群"
                            NS[路由信息管理]
                        end
                        
                        subgraph "Broker 集群"
                            B1[Broker-1<br/>Topic-A: Queue0,1<br/>Topic-B: Queue0]
                            B2[Broker-2<br/>Topic-A: Queue2,3<br/>Topic-C: Queue0,1]
                            B3[Broker-3<br/>Topic-B: Queue1,2<br/>Topic-C: Queue2,3]
                        end
                        
                        subgraph "生产者"
                            P1[Producer-1]
                            P2[Producer-2]
                        end
                        
                        subgraph "消费者"
                            C1[Consumer-1]
                            C2[Consumer-2]
                        end
                        
                        P1 & P2 -.获取路由.-> NS
                        C1 & C2 -.获取路由.-> NS
                        P1 & P2 -->|发送消息| B1 & B2 & B3
                        B1 & B2 & B3 -->|拉取消息| C1 & C2
                        
                        style NS fill:#667eea,color:#fff
                        style B1 fill:#764ba2,color:#fff
                        style B2 fill:#764ba2,color:#fff
                        style B3 fill:#764ba2,color:#fff
                </div>
            </div>

            <!-- Topic 核心作用 -->
            <div class="highlight-box">
                <h3 class="text-xl font-semibold mb-4">
                    <i class="fas fa-star text-purple-600 mr-2"></i>Topic 的核心作用
                </h3>
                <div class="grid md:grid-cols-2 gap-4">
                    <div>
                        <h4 class="font-semibold text-purple-700 mb-2">
                            <i class="fas fa-folder-tree mr-2"></i>消息分类
                        </h4>
                        <p class="text-gray-700">按业务领域划分消息，如订单消息、用户消息、日志消息等，每个 Topic 对应独立业务场景。</p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-purple-700 mb-2">
                            <i class="fas fa-shield-alt mr-2"></i>订阅隔离
                        </h4>
                        <p class="text-gray-700">不同消费者组可订阅不同 Topic，消费者只能消费其订阅的 Topic 中的消息。</p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-purple-700 mb-2">
                            <i class="fas fa-user-lock mr-2"></i>权限控制
                        </h4>
                        <p class="text-gray-700">可基于 Topic 进行权限控制，限制哪些生产者可以发送、哪些消费者可以订阅。</p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-purple-700 mb-2">
                            <i class="fas fa-tachometer-alt mr-2"></i>性能调优
                        </h4>
                        <p class="text-gray-700">可针对不同 Topic 设置不同的队列数，高并发 Topic 可配置更多队列以提高吞吐量。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Tag 使用方式 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">Tag 的使用方式和优势</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="card-hover p-6 rounded-xl">
                    <h3 class="text-xl font-semibold mb-4">
                        <i class="fas fa-tag text-purple-600 mr-2"></i>Tag 的基本概念
                    </h3>
                    <p class="text-gray-600 mb-4">Tag 是 RocketMQ 中消息的二级分类，附加在 Topic 之上，用于在同一 Topic 下进一步区分不同类型的消息。</p>
                    
                    <h4 class="font-semibold mb-2">实现方式</h4>
                    <ul class="space-y-2 text-gray-600">
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>Tag 作为消息的属性字段存储</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>随消息一起发送到 Broker</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>物理上与消息体一起存储在 CommitLog 中</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>不会创建额外的物理队列，轻量级设计</li>
                    </ul>
                </div>
                
                <div class="card-hover p-6 rounded-xl">
                    <h3 class="text-xl font-semibold mb-4">
                        <i class="fas fa-gem text-purple-600 mr-2"></i>Tag 的核心优势
                    </h3>
                    <div class="space-y-3">
                        <div>
                            <h4 class="font-semibold text-purple-700">消息精细分类</h4>
                            <p class="text-gray-600">在一个 Topic 内进行更细粒度的消息分类，如"订单Topic"下可有"创建订单"、"支付订单"、"取消订单"等不同 Tag。</p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-purple-700">消费端过滤</h4>
                            <p class="text-gray-600">消费者可按 Tag 订阅，只接收感兴趣的消息子集，减少无效消息处理。</p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-purple-700">降低系统复杂度</h4>
                            <p class="text-gray-600">避免创建过多 Topic 导致的管理复杂性，相关业务消息归入同一 Topic